package com.wencst.generateJPA;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.wencst.generateJPA.bean.TableBean;
import com.wencst.generateJPA.builder.IBuilder;
import com.wencst.generateJPA.builder.java.impl.ControllerBuilder;
import com.wencst.generateJPA.builder.java.impl.DaoBuilder;
import com.wencst.generateJPA.builder.java.impl.DomainBuilder;
import com.wencst.generateJPA.builder.java.impl.ServiceBuilder;
import com.wencst.generateJPA.builder.web.impl.DataPageBuilder;
import com.wencst.generateJPA.builder.web.impl.DetailPageBuilder;
import com.wencst.generateJPA.builder.web.impl.ListPageBuilder;
import com.wencst.generateJPA.config.CoreContext;
import com.wencst.generateJPA.database.IDatabase;
import com.wencst.generateJPA.database.impl.DefaultDB;

public class StartRun {

	public static void main(String[] args) {
		build2();
	}
	public static void build2() {
		CoreContext coreContext = config();
		IDatabase db = new DefaultDB(coreContext);
		List<TableBean> ltb = db.getAllTables();
		IBuilder ib = null;
		for (TableBean tb : ltb) {
			coreContext.setTb(tb);
//			ib = new DomainBuilder(coreContext);
//			ib.build();
//			ib = new DaoBuilder(coreContext);
//			ib.build();
//			ib = new ServiceBuilder(coreContext);
//			ib.build();
//			ib = new ControllerBuilder(coreContext);
//			ib.build();
			ib = new ListPageBuilder(coreContext);
			ib.build();
			ib = new DataPageBuilder(coreContext);
			ib.build();
			ib = new DetailPageBuilder(coreContext);
			ib.build();
			System.out.println(JSONObject.toJSONString(tb));
		}
	}
	public static CoreContext config() {
		CoreContext coreContext = new CoreContext();
		coreContext.setAuthorName("wencst");
		coreContext.setParentPackage("com.wencst.demo.test2");
		coreContext.setURL("jdbc:mysql://localhost:3306/apstools?useSSL=false&useUnicode=true&characterEncoding=utf8");
		coreContext.setUsername("root");
		coreContext.setPassword("root");
		coreContext.setDriver("com.mysql.jdbc.Driver");
		coreContext.addTableNames("product_plan");
		return coreContext;
	}

}
